# -*- coding:utf-8 -*-
class Solution:
    def IsPopOrder(self, pushv, popv):
        # write code here
        if pushv==[] or popv == []:
            return None
        stack = []
        for i in range(len(pushv)):
            stack.append(pushv[i])
            if stack[-1] != popv[0]:
                continue
            stack.pop()
            popv.pop(0)
        while len(stack)>0 and stack[-1] == popv[0]:
            stack.pop()
            popv.pop(0)
        if len(stack)==0:
            return True
        else:
            return False

a = [1,2,3,4,5]
b = [4,5,3,2,1]
s = Solution()
c = s.IsPopOrder(a,b)
print(c)